// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import 'lib-flexible/flexible'
import { setToken } from '@/utils/auth'

import { Button, Swipe, SwipeItem, Lazyload, Icon, Toast, Dialog, Field, Popup, Picker, Loading, Image as VanImage } from 'vant'

Vue.config.productionTip = false

Vue.use(Button)
Vue.use(Swipe)
Vue.use(SwipeItem)
Vue.use(Lazyload)
Vue.use(Icon)
Vue.use(Toast)
Vue.use(Picker)
Vue.use(Dialog)
Vue.use(Popup)
Vue.use(Field)
Vue.use(VanImage)
Vue.use(Loading)

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  if (to.query.token) {
    // 获取地址栏token进行token更新
    setToken(to.query.token)
  }
  next()
  // if (to.query.token) {
  //   setToken(to.query.token)
  //   next()
  // } else {
  //   if (getToken()) {
  //     next()
  //   } else {
  //     dd.reLaunch({
  //       url: '/pages/login/login'
  //     })
  //   }
  // }
})

/* eslint-disable no-new */
new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
